const { $fn, $wx, img, $http, globalData } = getApp()
Page({
	data: {
		img,
		data:[],
		list:[
			{ icon:'ico_car', title:'推荐车辆', subTitle:'Recommended vehicles', url:'/pages/fast-recommend/index' },
			{ icon:'ico_account', title:'我的账单', subTitle:'My Account',url:'/pages/my-bill/index' },
			{ icon:'ico_info', title:'我的资料', subTitle:'My information',  url:'/pages/my-info/index' },
			{ icon:'ico_confirm', title:'我的确认单', subTitle:'My confirmation', url:'/pages/confirm-bill/index' },
		],
		user: {},
		// 获取微信用户信息
		canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
		userType: 0 // 推广员
	},
	onLoad(){
		const user = $wx.local('user')
		const { user_type } = user
		if(user_type === 1){ // 站长
			this.setData({ 
				list: [
					{ icon:'ico_info', title:'我的资料', subTitle:'My information',  url:'/pages/my-info/index' },
					{ icon:'ico_next', title:'我的下级', subTitle:'My subordinate',  url:'/pages/my-next/index' },
					{ icon:'ico_account', title:'我的账单', subTitle:'My Account',url:'/pages/my-bill/index' },
					{ icon:'ico_confirm', title:'我的确认单', subTitle:'My confirmation', url:'/pages/confirm-bill/index' },
				],
				userType:user_type,
				user
			})
		}else if(user_type === 2){ // 驾驶员
			this.setData({ 
				list: [
					{ icon:'ico_register', title:'我的登记', subTitle:'My register',  url:'/pages/register/index' },
					{ icon:'ico_report', title:'我的报告', subTitle:'My Report',url:'/pages/my-report/index' },
				],
				userType:user_type,
				user
			})
		}else{
			this.setData({ user })
		}
		// 
		if(user_type === 0){
			$http.pull(this,'user.myCount', { loading:false })
		}
	},
	onRefresh(options){
		console.log($wx.local('user'))
		this.setData({ user: $wx.local('user')})
	},
	logout(){
		$wx.modal({
			content:'确认退出登录？',
			success:()=>{
				$http.submit(null,'user.logout').then(()=>{
					$wx.localClear()
					$wx.replace('/pages/login/index')
				})
			}
		})
	}
})
